package com.oocl.o2o.merchant.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.GenericGenerator;

import com.fasterxml.jackson.annotation.JsonFormat;

/**
 * 购物车中的商品信息
 * 
 * @author XIEMI2
 *
 */
@Entity
@Table(name = "order_info")
@GenericGenerator(name = "order_info_id_generator", strategy = "uuid")
public class OrderInfo {
	@Id
	@GeneratedValue(generator = "order_info_id_generator")
	@Column(columnDefinition = "char(32)")
	private String id;
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "merchant_id")
	private Merchant merchant;

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "customer_id")
	private Customer customer;
	@ManyToOne
	@JoinColumn(name = "receiver_info_id", columnDefinition = "char(32)")
	private ReceiverInfo receiverInfo;
	@ElementCollection(fetch = FetchType.EAGER)
	@CollectionTable(name = "order_item", joinColumns = @JoinColumn(name = "order_item_id", columnDefinition = "char(32)"))
	private List<OrderItem> items = new ArrayList<OrderItem>();
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "order_date")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
	private Date orderDate;
	@Enumerated(EnumType.STRING)
	@Column(name = "order_status")
	private OrderStatus orderStatus;
	private Double totalMoney;
	private Integer isComplaint = 0;

	public OrderInfo() {
	}

	public OrderInfo(Merchant merchant, Customer customer, ReceiverInfo receiverInfo, List<OrderItem> items,
			Date orderDate, OrderStatus orderStatus) {
		this.merchant = merchant;
		this.customer = customer;
		this.receiverInfo = receiverInfo;
		this.items = items;
		this.orderDate = orderDate;
		this.orderStatus = orderStatus;
	}

	public String getId() {
		return id;
	}

	public Merchant getMerchant() {
		return merchant;
	}

	public void setMerchant(Merchant merchant) {
		this.merchant = merchant;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public ReceiverInfo getReceiverInfo() {
		return receiverInfo;
	}

	public void setReceiverInfo(ReceiverInfo receiverInfo) {
		this.receiverInfo = receiverInfo;
	}

	public List<OrderItem> getItems() {
		return items;
	}

	public void setItems(List<OrderItem> items) {
		this.items = items;
	}

	public Date getOrderDate() {
		return orderDate;
	}

	public void setOrderDate(Date orderDate) {
		this.orderDate = orderDate;
	}

	public OrderStatus getOrderStatus() {
		return orderStatus;
	}

	public void setOrderStatus(OrderStatus orderStatus) {
		this.orderStatus = orderStatus;
	}

	public Double getTotalMoney() {
		return totalMoney;
	}

	public void setTotalMoney(Double totalMoney) {
		this.totalMoney = totalMoney;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Integer getIsComplaint() {
		return isComplaint;
	}

	public void setIsComplaint(Integer isComplaint) {
		this.isComplaint = isComplaint;
	}

}
